package com.example.hm_dtfkz.util;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;

import java.util.List;

/**
 * FileName: AccessibilityUtil
 * Author: admin
 * Date: 2021/12/10 15:29
 * Description:
 */
public class AccessibilityUtil {

    /**
     * 判断是否有辅助功能权限
     * @return true 已开启
     *          false 未开启
     */
    public static boolean isAccessibilitySettingsOn(Context context,String className){
        if (context == null){
            return false;
        }

        ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> runningServices =
                activityManager.getRunningServices(100);// 获取正在运行的服务列表
        if (runningServices.size()<0){
            return false;
        }
        for (int i=0;i<runningServices.size();i++){
            ComponentName service = runningServices.get(i).service;
            if (service.getClassName().equals(className)){
                return true;
            }
        }
        return false;
    }
}